#!/usr/bin/env python
# encoding: utf-8
# @author: Lin Han
# @contact: voldemort22@126.com
# @file: update_rpsType_1_start.py
# @time: 2021/4/14 9:25
# @desc:
import pymongo

from .utils.mongo_tools import update_mongo_value
from .views.configs import MONGO_URL, MONGO_DATABASE_NAME, HISTORY_CLAMP_COLLECTION

myclient = pymongo.MongoClient(MONGO_URL)
mydb = myclient[MONGO_DATABASE_NAME]
history_clamp = mydb[HISTORY_CLAMP_COLLECTION]

cursor = history_clamp.find({})
for i in cursor:
    print(i["number"])
    i.pop("_id")
    temp_dict = {}
    try:
        rpsType = i["tag"]["rpsType"]
        for key, value in enumerate(rpsType.values()):
            temp_dict.update({key + 1: value})
        i["tag"]["rpsType"] = temp_dict
        update_mongo_value(
            filter_condition={"number": i["number"]},
            new_value={"$set": {"tag": i["tag"]}},
            database_name=MONGO_DATABASE_NAME,
            collection_name=HISTORY_CLAMP_COLLECTION,
        )
    except:
        pass


cursor = history_clamp.find({})
for i in cursor:
    try:
        if min(list(i['tag']['rpsType'])) == "0":
            print(i)
    except:
        pass
